<?php

namespace App\Http\Controllers\Admin;

use App\Services\UploadService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;



class UploadController extends Controller
{

    private  $service;

    public function __construct(UploadService $service)
    {
        $this->service = $service;
    }

    public function fileupload($disk = 'public', Request $request, $form_file_name = 'image-file')
    {

        if ($disk) {
            $this->service->disk($disk);
        }

        $url = $this->service->formUpload($form_file_name, Auth::id(), $request);
        return ['status' => ($url === false ? 'fail' : 'success'), 'message' => $this->service->getError(), 'url' => $url, 'data' => ['url' => $url]];
    }

}
